<?php

class FP_Image_Text
{
  const PNG = 'png';
  const JPEG = 'jpg';
  const GIF = 'gif';

  protected $_image = null;

  public function __construct($pText, $pWidth, $pHeight, $pX=0, $pY=0, $pSize=2, array $pFontColor=array(0,0,0), array $pBackgroundColor=array(255,255,255)){

    $this->_image = imagecreate($pWidth, $pHeight);
    $bg_color = imagecolorallocate($this->_image, $pBackgroundColor[0],  $pBackgroundColor[1],  $pBackgroundColor[2]);
    $fg_color = imagecolorallocate($this->_image, $pFontColor[0],  $pFontColor[1],  $pFontColor[2]);
    imagestring($this->_image, $pSize, $pX, $pY, $pText, $fg_color);
  }

  public function stream($pFormat=self::PNG){
    switch ($pFormat){
    case self::PNG:
      return imagepng($this->_image);
    case self::JPEG:
      return imagejpeg($this->_image);
    case self::GIF:
      return imagegif($this->_image);
    default:
      throw new FP_Image_Exception("Unsupported format $pFormat", FP_Image_Exception::UNSUPPORTED_FORMAT);
    }
  }
}

?>